<?php
//后台首页控制器
namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;

class HomeController extends CommonController
{
    //加载后台网站首页
    public function home()
    {
		$list1 = \DB::table("friendlink")->get();
		$list2 = \DB::table('config')->get();
		
		return view("home.index",['list1'=>$list1,'list2'=>$list2[0]]);
    }
	
	public function shouchang()//收藏
	{	
		return view("home.shouchang");
	}
	
	//加载收藏模板
    public function cat($id)
    {
        //return "加载收藏页".$id;
        $data = \DB::table("goodslist")->where("id","=",$id)->get();
        $name = $data['0']->name;
        $money = $data['0']->yprice;
        $status = $data['0']->status;
        $cimg = $data['0']->goodsImg;
        /*var_dump($name);
        var_dump($money);
        var_dump($status);
        var_dump($cimg);
        die;*/
        $uid = session('id');
        $list = \DB::table("collect")->where("uid","=",$uid)->get();
        if($list){
            return "此商品已收藏";
        }else{
            //-------------uid为用户id-----sid为商品id---------------------
            $db = \DB::table("collect")->insertGetId(
                    array('uid'=>"$uid",'sid'=>"$id",'title'=>"$name",'money'=>"$money",'state'=>"$status",'cimg'=>"$cimg")
                    );
            if($db>0){
                $list = \DB::table("collect")->where("uid","=",$uid)->get();
                return view("home/goods.collect",['list'=>$list]);
            }else{
                return "收藏失败";
            }
        }
    }
	public function show($id)
    {
        //------------------传入id为商品id------------用户id在session中取---------
        //return "返回收藏成功页面";
        $uid = session('id');
        $list = \DB::table("collect")->where("uid","=","$uid")->get();
        //dd($list);
        return view("home/goods/collect",['list'=>$list]);
    }
	public function destroy($id)
    {
        //-----------------------------传入id为-----------------------------------
        //return "执行收藏删除.$id";
        $uid = session('id');
        $m = \DB::table("collect")->where("uid",$uid)->where("id",$id)->delete();
        if($m>0){
            $list = \DB::table("collect")->where("uid","=",'$uid')->get();
            return view("home/goods/collect",['list'=>$list]);
        }else{
            return "删除失败！";
        }
    }
	
	public function users()
	{
		return view("home.users");
	}
	
	public function jf()
	{
		
		return view("home.jf");
	}
	
	

}
